# -*- coding: UTF-8 -*-

from types import *




import config
import os
import glob
import sys
import re

from distutils.file_util import *

import wx
try:
  from features.UI.common import windict
except:
  print "could not import windict"

class Stdout:

  def __init__(self):
    self.textctrl = None
    self.oldstdout = sys.stdout
    try:
        
        wd = windict.WinDict()       
        wd.set("oldstdout", self.oldstdout)
        #print wd
        id = wd.get("CONSOLE")
        #print id
        self.console = wx.FindWindowById(id)
        sys.stdout = RedirectText(self.console)
        
    except Exception, e:
      print e
      print "could not find console window"
    
  def getOld(self):
    return self.oldstdout
  
  def redirect(self, target):    
    sys.stdout = target
  
  
  def __del__(self):
    pass

  
class RedirectText:
    def __init__(self,aWxTextCtrl):
                self.out=aWxTextCtrl

    def write(self,string):
                self.out.AppendText(string)
                #self.out.WriteText(string) 
